//--------------------------------------------------------
export const STORAGE_KEY_USER_INFO = "user_info";
//--------------------------------------------------------
// 基础的存储
/**
 *
 * @param {string} key
 * @param {string} value
 */
export function saveString(key, value) {
  localStorage.setItem(key, value);
}

/**
 *
 * @param {string} key
 * @returns {string}
 */
export function getString(key) {
  const value = localStorage.getItem(key);
  return value ?? "";
}

/**
 *
 * @param {string} key
 * @param {number} value
 */
export function saveNumber(key, value) {
  localStorage.setItem(key, value + "");
}

/**
 * 这里考虑到如果存储的数据有问题，指定的为特定值
 * 非数字：-1
 * 无限数：-2（可能是 /0）导致（待验证）
 *
 * @param {string} key
 * @returns
 */
export function getNumber(key) {
  const value = localStorage.getItem(key);
  const convertValue = new Number(value).valueOf();
  if (!convertValue) {
    convertValue = 0;
  }
  if (Number.isNaN(convertValue)) {
    convertValue = -1;
  }
  if (Number.isFinite(convertValue)) {
    convertValue = -2;
  }
  return convertValue;
}

/**
 *
 * @param {string} key
 * @param {boolean} value
 */
export function saveBoolean(key, value) {
  localStorage.setItem(key, value);
}

export function getBoolean(key) {
  const value = localStorage.getItem(key);
  return value == "true" ? true : value == "false" ? false : undefined;
}
